import Vue from 'vue'
import Vuet from 'vuet'
import * as request from '../request'
import * as storage from '../storage'
import config from '../config'

Vue.use(Vuet)
let avatar = config.website + '/wap/static/images/avatar.png'

export default new Vuet({
  pathJoin: '-',
  modules: {
    // 商品分类列表
    goodsClassList: {
      data () {
        return []
      },
      async fetch ({state, route, params, path}) {
        const data = await request.getGoodsClassList()
        return data
      }
    },
    // 收货地址列表
    addressList: {
      data () {
        return {requested: false, loading: true, data: []}
      },
      async fetch() {
        const response = await request.getAddressList()
        return {requested: true, loading: false, data: response.data}
      }
    },
    // 银行卡信息
    bankList: {
      data () {
        return {requested: false, loading: true, data: []}
      },
      async fetch() {
        const response = await request.getBankList()
        return {requested: true, loading: false, data: response}
      }
    },
    // 可选银行卡信息列表
    allbankList: {
      data () {
        return {requested: false, loading: true, data: []}
      },
      async fetch() {
        const response = await request.getAllBankList()
        return {requested: true, loading: false, data: response}
      }
    },
    // 商店地址列表
    shopAddressList: {
      data () {
        return {requested: false, loading: true, data: []}
      },
      async fetch() {
        const response = await request.getShopAddressList()
        return {requested: true, loading: false, data: response}
      }
    },
    // 临时保存的购物车选中的商品id列表，用于请求生成订单（购物车->订单确认 之间的数据传递）
    // selectedCartIdList: {
    //   data () {
    //     return []
    //   },
    //   async fetch() {
    //     return []
    //   }
    // },
    // 用户信息
    memberInfo: {
      data () {
        return storage.getMemberInfo() || {member_mobile: '', balance: 0, integral: 0, member_avatar: avatar, qrcode_image: '', member_name: '', member_id: ''}
      },
      async fetch() {
        const data = await request.getMemberInfo()
        if (!data.member_avatar || data.member_avatar == '') {
          data.member_avatar = avatar
        }
        storage.setMemberInfo(data)
        return data
      }
    },
    // 退款原因列表
    refundMoneyReasonList: {
      data () {
        return []
      },
      async fetch() {
        const data = await request.getRefundReasonList('0')
        return data
      }
    },
    // 退货原因列表
    refundGoodsReasonList: {
      data () {
        return []
      },
      async fetch() {
        const data = await request.getRefundReasonList('1')
        return data
      }
    },
    // 物流列表
    expressList: {
      data () {
        return []
      },
      async fetch() {
        const data = await request.getExpressList()
        return data
      }
    },
    // app微信登录的微信信息
    wxInfo: {
      data () {
        return {}
      }
    }
  }
})
